def help():
return """
- Usage: xm getlabel dom <configfile>"
- xm getlabel res <resource>\n"
+ Usage: xm getlabel dom <configfile>
+ xm getlabel res <resource>
+
This program shows the label for a domain or resource."""
def get_resource_label(resource):
try:
access_control = dictio.dict_read("resources", file)
except:
- security.err("Resource label file not found")
+ raise OptionError("Resource label file not found")
# get the entry and print label
if access_control.has_key(resource):
label = access_control[resource][1]
print "policy="+policy+",label="+label
else:
- security.err("Resource not labeled")
+ raise security.ACMError("Resource not labeled")
def get_domain_label(configfile):
# open the domain config file
fd = None
- file = None
if configfile[0] == '/':
fd = open(configfile, "rb")
else:
for prefix in [".", "/etc/xen"]:
- file = prefix + "/" + configfile
- if os.path.isfile(file):
- fd = open(file, "rb")
+ abs_file = prefix + "/" + configfile
+ if os.path.isfile(abs_file):
+ fd = open(abs_file, "rb")
break
if not fd:
- security.err("Configuration file '"+configfile+"' not found.")
+ raise OptionError("Configuration file '%s' not found." % configfile)
# read in the domain config file, finding the label line
ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
# send error message if we didn't find anything
if acline == "":
- security.err("Domain not labeled")
+ raise security.ACMError("Domain not labeled")
# print out the label
(title, data) = acline.split("=", 1)
print data
-def main (argv):
+def main(argv):
if len(argv) != 3:
raise OptionError('Requires 2 arguments')
raise OptionError('First subcommand argument must be "dom" or "res"')
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except Exception, e:
+ sys.stderr.write('Error: %s\n' % str(e))
+ sys.exit(-1)
+